import request from '@/utils/request'
import { AxiosPromise } from 'axios'

/**
 * 菜单数据接口定义
 */
interface MenuItem {
  id: number
  pid: number
  title: string
  icon: string
  component: string
  redirect: string
  sort: number
  status: number
  mig_src: string
  children?: MenuItem[]
}

interface SystemConfig {
  [key: string]: any
}

interface WebConfig {
  [key: string]: any
}

interface AdminInfo {
  id: number
  name: string
  [key: string]: any
}

interface MenuResponse {
  code: number
  msg: string
  data: {
    menu: MenuItem[]
    admin: AdminInfo
    system: SystemConfig
    web: WebConfig
  }
}

/**
 * 获取菜单列表
 * @returns 菜单列表数据
 */
export const getMenuList = (): AxiosPromise<MenuResponse> => {
  return request({
    url: '/api/auth/userInfo',
    method: 'get',
  })
}

/**
 * 更新菜单的mig_src字段
 * @param menuId 菜单ID
 * @returns API响应
 */
export const updateMenuMigSrc = (menuId: number): AxiosPromise => {
  return request({
    url: `/api/home/menu/updateMigSrc`,
    method: 'post',
    data: { id: menuId },
  })
}
